#! /usr/bin/python
# encoding=utf-8
# Created by Fenglu Niu on 2025/5/6 21:39
from sqlmodel import Session, select

import common
from api.entity import Conversation


class ConversationService(object):

    @staticmethod
    def create_conversation(conversation: Conversation, session: Session, autocommit: bool = True):
        try:
            session.add(conversation)
            if autocommit:
                session.commit()
        except Exception as e:
            common.get_logger().error('创建会话报错：{}', e)
            session.rollback()

    @staticmethod
    def list_conversation(stu_no: str, session: Session):
        return session.exec(select(Conversation).where(Conversation.stu_no == stu_no)).all()
